package jw3.c2.controller;

import jw3.c2.utils.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

public class OpensController {
    //1、全查：展示   2、模糊查
    public static Vector<Vector<Object>> getAll(String Customer_Name){
        String sql = "";
        if (Customer_Name.equals("")){//全查
            sql="select * from opens";
        }else if (!Customer_Name.equals("")){//模糊查
            sql="select * from opens where Customer_Name like ? ";
        }

        //1、构造Vector类型用于赋值给表格
        Vector<Vector<Object>> data=new Vector<Vector<Object>>();
        try {
            Connection conn= DBConnection.getConnection();
            PreparedStatement ps=conn.prepareStatement(sql);
            if (!Customer_Name.equals("")){ //参数化sql语句只在模糊查时进行
                ps.setString(1,"%"+Customer_Name+"%");
            }

            ResultSet rs=ps.executeQuery();
            while (rs.next()){
                //创造对象，每次放一条数据
//                UserInfo ui=new UserInfo();
                Vector<Object> ui=new Vector<Object>();

                //将每个字段放入对象
                ui.add(rs.getInt("C_ID"));
                ui.add(rs.getInt("Vip_ID"));
                ui.add(rs.getString("Customer_Name"));
                ui.add(rs.getString("Customer_Sex"));
                ui.add(rs.getString("Customer_Phone"));
                ui.add(rs.getString("Customer_Card_ID"));
                ui.add(rs.getString("Customer_Address"));
                ui.add(rs.getInt("O_ID"));
                ui.add(rs.getDate("Start_Time"));
                ui.add(rs.getInt("Start_Days"));
                ui.add(rs.getInt("Rooms_Type_ID"));
                ui.add(rs.getDate("B_Time"));
                ui.add(rs.getInt("B_Days"));



                //每次将一条数据加入到集合
                data.add(ui);
            }
            DBConnection.close(rs,ps,conn);
            return data;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
